<?php
include_once("connection.php");
class allUser
{
	var $username;
	var $password;
	var $type;
	var $fullName;
	var $address;
	var $contact;
	var $email;

   function User($u, $p,$type) // constructor
   {
      $this->username = $u;
      $this->password = $p;
	  $this->type=null;
   }

   function insert($u, $p, $f, $a, $c, $e, $g, $d, $m, $y)
   {
      $array = array($y, $m, $d);
		 $dob = implode("-",$array);
		 $query = "insert into student values('$u','$g','$dob','$f','$a','$c','$e')";
      $result = mysql_query($query);
		 if($result)
	    {
				$query = "insert into user values('$u','$p')";
				$result= mysql_query($query);
       }
			return $result;
   }
   function delete($u)
   {
	$flag=false;
	$query = "select * from student where username='$u'";
      $result = mysql_query($query);
 	if($row = mysql_fetch_row($result))
      {
		$query = "delete from user where username='$u'";
		$flag= mysql_query($query);
		$query = "delete from student where username='$u'";
		$flag= mysql_query($query);
      }
	return $flag;
   }
   function update($u, $c, $e)
   {
	$flag=false;
	$query = "select * from student where username='$u'";
      $result = mysql_query($query);
 	if($row = mysql_fetch_row($result))
      {
		$query = "update student set ContactNumber='$c',EmailAddress='$e' where username='$u'";
		$flag= mysql_query($query);
      }
	return $flag;
   }
   function viewCourses($u,$s)
   {
			$query = "select c.CName,c.CTeacher from course c,result r where c.Code=r.CourseCode and r.username='$u' and r.semesterNo='$s'";
      $result = mysql_query($query);
      return $result;
   }   
   function login()
   {
   	$flag=false;
   	$query  = "select * from users";
		$result = mysql_query($query);
		while($row = mysql_fetch_row($result))
		{
    	if($row[0]==$this->username && $row[1]==$this->password)
   	  	 $flag=true;

		} 
		return $flag;		
   }
   function gohome()
   {
	   $query  = "select * from users";
		$result = mysql_query($query);
		while($row = mysql_fetch_row($result))
		{
    	if($row[0]==$this->username && $row[1]==$this->password && $row[2]==1)
		{
			header("Location:/Student/studentHome.php");
		}
		else if($row[0]==$this->username && $row[1]==$this->password && $row[2]==2)
		{
			header("Location:/Clerk/clerkHome.php");
		}
		else if($row[0]==$this->username && $row[1]==$this->password && $row[2]==1)
		{
			header("Location:/chairman/ChairmanHome.php");
		}
		}
		header("Location:/student/unidentifieduser.php"); 
		return $flag;
   }
   static function authenticate($u, $p)
   {
      // checks against db
   }
   function logout()
   {
      // does logout procedures
   }
}
?>